﻿using System.Collections.Generic;
using MathematicallySafe.Armourer.Base;
using MathematicallySafe.HeadCounter.Data;
using MathematicallySafe.HeadCounter.Data.Models;
using StructureMap;

namespace MathematicallySafe.HeadCounter.ViewModels
{
    public class GeneralOptionsViewModel : ViewModelBase
    {
        private readonly Options _options = ObjectFactory.GetInstance<IHeadCounterService>().Options;

        private readonly List<WowRegion> _regions = new List<WowRegion>
                                                        {
                                                            WowRegion.EU,
                                                            WowRegion.US,
                                                            WowRegion.CN,
                                                            WowRegion.KR,
                                                            WowRegion.TW
                                                        };

        public string GuildName
        {
            get { return _options.GuildName; }
            set
            {
                _options.GuildName = value;

                // todo this should work via events or something
                var guild = ObjectFactory.GetInstance<IHeadCounterService>().Guild;
                guild.Name = value;

                OnPropertyChanged("GuildName");
            }
        }

        public string Realm
        {
            get { return _options.Realm; }
            set
            {
                _options.Realm = value;
                OnPropertyChanged("Realm");
            }
        }

        public WowRegion Region
        {
            get { return _options.Region; }
            set
            {
                _options.Region = value;
                OnPropertyChanged("Region");
            }
        }

        public IEnumerable<WowRegion> Regions
        {
            get { return _regions; }
        }

        public int iLevelBase
        {
            get { return _options.iLevelBase; }
            set
            {
                _options.iLevelBase = value;
                OnPropertyChanged("iLevelBase");
            }
        }

        public int iLevelProgression
        {
            get { return _options.iLevelProgression; }
            set
            {
                _options.iLevelProgression = value;
                OnPropertyChanged("iLevelProgression");
            }
        }

        public int ShortPeriodLength
        {
            get { return _options.ShortPeriodLength; }
            set
            {
                _options.ShortPeriodLength = value;
                OnPropertyChanged("ShortPeriodLength");
            }
        }

        public int LongPeriodLength
        {
            get { return _options.LongPeriodLength; }
            set
            {
                _options.LongPeriodLength = value;
                OnPropertyChanged("LongPeriodLength");
            }
        }

        public Period DefaultPeriod
        {
            get { return _options.DefaultPeriod; }
            set
            {
                _options.DefaultPeriod = value;
                OnPropertyChanged("DefaultPeriod");
            }
        }

        public int MinAttendancePercent
        {
            get { return _options.MinAttendancePercent; }
            set
            {
                _options.MinAttendancePercent = value;
                OnPropertyChanged("MinAttendancePercent");
            }
        }
             
        public int MinAttendanceCount
        {
            get { return _options.MinAttendanceCount; }
            set
            {
                _options.MinAttendanceCount = value;
                OnPropertyChanged("MinAttendanceCount");
            }
        }

        public int MaxEffectiveAttendancePercent
        {
            get { return _options.MaxEffectiveAttendancePercent; }
            set
            {
                _options.MaxEffectiveAttendancePercent = value;
                OnPropertyChanged("MaxEffectiveAttendancePercent");
            }
        }

        public double HighAttendancePercentage
        {
            get { return _options.HighAttendancePercentage; }
            set
            {
                _options.HighAttendancePercentage = value;
                OnPropertyChanged("HighAttendancePercentage");
            }
        }

        public double GoodAttendancePercentage
        {
            get { return _options.GoodAttendancePercentage; }
            set
            {
                _options.GoodAttendancePercentage = value;
                OnPropertyChanged("GoodAttendancePercentage");
            }
        }

        public double FairAttendancePercentage
        {
            get { return _options.FairAttendancePercentage; }
            set
            {
                _options.FairAttendancePercentage = value;
                OnPropertyChanged("FairAttendancePercentage");
            }
        }

        public bool AutoApplyAttendanceCreditToDeletedRaiders
        {
            get { return _options.AutoApplyAttendanceCreditToDeletedRaiders; }
            set
            {
                _options.AutoApplyAttendanceCreditToDeletedRaiders = value;
                OnPropertyChanged("AutoApplyAttendanceCreditToDeletedRaiders");
            }
        }
    }
}
